<template>
  <div class="home-singer">
    <div class="title">
      <h1>云村出品</h1>
      <div class="gengduo">
        <span>更多＞</span>
      </div>
    </div>
    <div class="wrapper" ref="wrapper">
      <!--滚动所需的容器-->
      <ul class="content" ref="content">
        <li
          v-for="(item, index) in listData"
          :key="index"
          @click="selectItem(item)"
        >
          <div class="pic">
            <van-image :src="item.cover" radius="10px" />
          </div>
          <span>{{ item.name }}</span>
          <span>{{ item.artistName }}</span>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { betterScrollHorizontal } from "../../common/betterScroll.js"; //引入betterscroll

export default {
  data() {
    return {
      listData: [],
    };
  },
  created() {
    this.getSingerListData();
  },
  methods: {
    getSingerListData() {
      this.$request("get", "/mv/first").then((res) => {
        // console.log(res);
        if (res.code == 200) {
          this.listData = res.data;
        }
        // 异步数据的处理
        betterScrollHorizontal(
          this,
          this.$refs.wrapper,
          this.$refs.content,
          this.listData.length,
          10
        ); //调用横向滚动的方法
      });
    },
    selectItem(item) {
      const id = item.singer_mid;
      this.$router.push({
        path: `/singerhome/${id}`,
      });
    },
  },
};
</script>
<style scoped>
.title {
  align-items: center;
  display: flex;
}
.title > h1 {
  width: 25%;
  margin-left: 20px;
  text-align: left;
  font-size: 22px;
}
.gengduo {
  display: flex;
  width: 70%;
  justify-content: flex-end;
}
.gengduo > span {
  border-radius: 15px;
  border: 1px solid rgb(175, 175, 175);
  padding-left: 7px;
  padding-right: 6px;
  padding-top: 4px;
  padding-bottom: 4px;
  font-size: 16px;
  color: black;
}
.wrapper {
  width: 100%; /** 容器的宽度就是屏幕的宽度 */
  overflow: hidden;
}

ul.content li {
  /* li默认使用块级元素 */
  display: inline-block; /**行内元素*/
  width: 10rem;
  vertical-align: top; /**垂直方向的algin顶满上一个div */
  margin-bottom: 50px;
}
ul.content li * {
  /**选取下面的所有元素*/
  margin: 0.1rem;
}
ul.content li > span {
  font-size: 0.8rem;
  color: rgb(41, 31, 24);
}
</style>